package com.example.jimanguang.Entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "user")
@Getter
@Setter
public class User extends  BaseEntity{
    @Transient//忽略到映射到数据库
    public static final int TYPE_BANNED=-1;//禁止访问的
    @Transient//忽略到映射到数据库
    public  static final int TYPE_ADMIN=0;//管理员状态
    @Transient//忽略到映射到数据库
    public static final int TYPE_READER=1;//阅读者状态

    @Transient//忽略到映射到数据库
    public static final int TYPE_CREATOR=2;//创作者状态

    private String nickName;//昵称
    private String userName;//账号

    private String enail;//邮箱
    private String phone;//手机号

    private String password;//用户密码

    private String avatar;//用户头像

    private int type;//用户状态


    private String salt;//用于储存账户随机码，保证密码的安全性
    @Temporal(TemporalType.TIMESTAMP)//确保实体类中的属性类型与数据库中的时间属性类型相匹配
    private Date createTime;//用户创建的时间
    @Temporal(TemporalType.TIMESTAMP)//确保实体类中的属性类型与数据库中的时间属性类型相匹配
    private Date updateTime;//用户信息修改的时间

   public User(){ //创建用户时更新时间相当于创建时间
      createTime=new Date();
      updateTime=createTime;
  }

     @OneToMany(mappedBy = "user")
     private List<Comments> comments=new ArrayList<>();
     @OneToMany(mappedBy = "user")
    private List<ReadingHIstory> hIstories=new ArrayList<>();
     @OneToMany(mappedBy = "user")
     private List<RewardComic> rewardComics=new ArrayList<>();
    @OneToMany(mappedBy = "user")
    private List<SubsribeComic> subsribeComics=new ArrayList<>();
    @OneToMany(mappedBy = "comics")
    private List<Collect> collects=new ArrayList<>();

    @OneToMany(mappedBy = "creator")
    private List<Appliction> applictions=new ArrayList<>();

   //序列化
    @JsonManagedReference
    public List<Comments> getComments(){return comments;}

    @JsonManagedReference
    public List<ReadingHIstory> getHIstories(){return hIstories;}

    @JsonManagedReference
    public List<RewardComic> getRewardComics(){return rewardComics;}

    @JsonManagedReference
    public List<SubsribeComic> getSubsribeComics(){return subsribeComics;}

    @JsonManagedReference
    public List<Collect> getCollects(){return collects;}

    @JsonManagedReference
    public List<Appliction> getApplictions(){return applictions;}

}
